import React, {Component} from 'react'
import { Switch, Route, Redirect } from 'react-router-dom'
export default class Index extends Component {
    render() {
        const {routes} = this.props
        const normalRoutes = routes.filter(item => !item.to)
        const redirectRoutes = routes.filter(item => item.from).map((item, key) => <Redirect key={key} from={item.from} to={item.to}></Redirect>)
        return(
            <Switch>
                {
                    normalRoutes && normalRoutes.map((item, key) => <Route key={key} path={item.path} 
                        render={props => <item.component {...props} routes={item.children}></item.component>}></Route>).concat(redirectRoutes)
                }
            </Switch>
        )
    }
}